package com.example.qxfw.rcyw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.entity.qx.SmallScaleStation;
import com.example.qxfw.rcyw.dto.StationDto;
import com.example.qxfw.rcyw.mapper.SmallScaleStationMapper;
import com.example.qxfw.rcyw.service.SmallScaleStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SmallScaleStationServiceImpl implements SmallScaleStationService {

    @Autowired
    private SmallScaleStationMapper smallScaleStationMapper;

    @Override
    public Map<String, StationDto> selectList() {
        HashMap<String,StationDto> stationMap = new HashMap<>();
        List<SmallScaleStation> smallScaleStations = smallScaleStationMapper.selectList1();
        for (SmallScaleStation smallScaleStation : smallScaleStations) {
            StationDto stationDto = new StationDto();
            stationDto.setStrStationId(smallScaleStation.getStationid().trim());
            stationDto.setStrStationName(smallScaleStation.getStationname().trim());
            stationDto.setStrCounty(smallScaleStation.getCounty().trim());
            stationDto.setDLat(Double.parseDouble(smallScaleStation.getLatitude().toString().trim()));
            stationDto.setDLon(Double.parseDouble(smallScaleStation.getLongitude().toString().trim()));
            if (!stationMap.containsKey(stationDto.getStrStationId())){
                stationMap.put(stationDto.getStrStationId(),stationDto);
            }
        }
        return stationMap;
    }

    @Override
    public List<SmallScaleStation> selectStation(String stationId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("stationid",stationId);
        List<SmallScaleStation> smallScaleStations = smallScaleStationMapper.selectList(queryWrapper);
        return smallScaleStations;
    }

    @Override
    public SmallScaleStation getById(String stationId) {
        return smallScaleStationMapper.selectById(stationId);
    }

    @Override
    public List<String> getStationName() {
        return smallScaleStationMapper.selectStationName();
    }

    @Override
    public List<String> getStationId(String stationName) {
        return smallScaleStationMapper.selectStationId(stationName);
    }

    @Override
    public List<SmallScaleStation> getList2() {
        return smallScaleStationMapper.selectList2();
    }

    @Override
    public List<String> getStatinoName(String city) {
        return smallScaleStationMapper.selectStationNameCity(city);
    }

    @Override
    public List<SmallScaleStation> getList3(String stationName) {
        return smallScaleStationMapper.selectList3(stationName);
    }

    @Override
    public List<SmallScaleStation> getList4() {
        return smallScaleStationMapper.selectList4();
    }

    @Override
    public List<String> getStationNameByCounty(String county) {
        return smallScaleStationMapper.selectStationNameByCounty(county);
    }

    @Override
    public List<String> getStationNameByCity(String city) {
        return smallScaleStationMapper.selectStationNameByCity(city);
    }

    @Override
    public List<String> getCounty() {
        return smallScaleStationMapper.selectCountry();
    }

    @Override
    public List<String> getCountryByStationId(String stationId) {
        return smallScaleStationMapper.selectCountryByStationId(stationId);
    }

    @Override
    public List<SmallScaleStation> getList5(String city) {
        return smallScaleStationMapper.selectList5(city);
    }

    @Override
    public List<SmallScaleStation> getList6(String city) {
        return smallScaleStationMapper.selectList(Wrappers.<SmallScaleStation>lambdaQuery()
                .eq(SmallScaleStation::getCity,city)
                .orderByAsc(SmallScaleStation::getStationid));
    }



}
